import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

class Crafter {
    public static Collection<Koszulka> zbrojownia= new LinkedList();


    public static void main(String[] args) {
      String zbrojownia_name  ="/Users/tomaszsocha/Desktop/";
      if (args.length >0 ) {
           zbrojownia_name  +=args[0];
        } else {
            zbrojownia_name  +="zk.csv";
        }
      File zkFile = new File(zbrojownia_name);


      Action action = new AbstractAction("Button Label") {
      // This method is called when the button is pressed
      public void actionPerformed(ActionEvent evt) {
        // Perform action...
      }
    };

    // Create the button from the action
      JButton button = new JButton(action);
       ActionListener actionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        System.out.println("I was selected.");
      }
    };

    MouseListener mouseListener = new MouseAdapter() {
      public void mousePressed(MouseEvent mouseEvent) {
        int modifiers = mouseEvent.getModifiers();
        if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
          // Mask may not be set properly prior to Java 2
          // See SwingUtilities.isLeftMouseButton() for workaround
          System.out.println("Left button pressed.");
        }
        if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {
          System.out.println("Middle button pressed.");
        }
        if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
          System.out.println("Right button pressed.");
        }
      }

      public void mouseReleased(MouseEvent mouseEvent) {
        if (SwingUtilities.isLeftMouseButton(mouseEvent)) {
          System.out.println("Left button released.");

        }
        if (SwingUtilities.isMiddleMouseButton(mouseEvent)) {
          System.out.println("Middle button released.");
        }
        if (SwingUtilities.isRightMouseButton(mouseEvent)) {
          System.out.println("Right button released.");
        }
        System.out.println();
      }
    };

    button.addActionListener(actionListener);
    button.addMouseListener(mouseListener);






      JPanel jpanel_0 = new JPanel();
      jpanel_0.setBackground(Color.pink);
      JList zk = new JList();

        try {
            zk.setListData(new Vector(initZbrojownia(zkFile,zbrojownia)));
       //     zk.setModel(initZbrojownia(zkFile));
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        for(int i=0;i<3;++i) jpanel_0.add(new JLabel("label"+i));
     
      JPanel jpanel_1 = new JPanel(new GridLayout(0,1));
      jpanel_1.setBackground(Color.cyan);
      for(int i=0;i<7;++i) jpanel_1.add(new JLabel("  label"+i+"  "));
      jpanel_0.add(button);
      jpanel_0.add(zk);
      JFrame frame = new JFrame();
      Container cp = frame.getContentPane();
      cp.add(jpanel_0,BorderLayout.WEST);
      cp.add(jpanel_1,BorderLayout.EAST);

      frame.pack();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);

   }


    
   public static Collection initZbrojownia(File fFile,Collection z) throws FileNotFoundException {
    Scanner scanner = new Scanner(fFile,"UTF-8");
    try {
      //first use a Scanner to get each line
      while ( scanner.hasNextLine() ){
          String line = scanner.nextLine() ;
          String pref = line.substring(0, line.indexOf(","));
          String suf =line.substring(line.indexOf(",")+1);
          z.add(new Koszulka(pref,suf));
      }

      Iterator it = z.iterator();
        while (it.hasNext()){
            System.out.println(((Koszulka) it.next()).getIngredients());
        }
    }
    finally {
      //ensure the underlying stream is always closed
      scanner.close();
    }


        return z;
    }

    public static DefaultListModel initZbrojownia(File fFile) throws FileNotFoundException {
    Scanner scanner = new Scanner(fFile,"UTF-8");
    DefaultListModel listModel = new DefaultListModel();
    try {
      //first use a Scanner to get each line
      while ( scanner.hasNextLine() ){
          String line = scanner.nextLine() ;
          String pref = line.substring(0, line.indexOf(","));
          String suf =line.substring(line.indexOf(",")+1);
          listModel.addElement(pref+" koszulka "+suf);
      }

      /*Iterator it = listModel.iterator();
        while (it.hasNext()){
            System.out.println(((Koszulka) it.next()).getIngredients());
        }
      */
    }
    finally {
      //ensure the underlying stream is always closed
      scanner.close();
    }


        return listModel;
    }


}